# -*- coding: utf-8 -*-
# @File    : hhhhh.py
# @Time    : 2022/2/25 13:33
# @Author  : bugger
import jsonpath as jsonpath
import pytest_check as check

from api_auto_test import logger
from tools.checkapi_tool_assert import Assert

# code, expected_code, msg = 201, 200, "hahha"
# try:
#     check.equal(code, expected_code)
#     logger.info(f"【断言status_code:successed】期望状态码: {expected_code} 【==】 实际状态码: {code}")
# except Exception as e:
#     logger.error(f"【断言status_code:failed】期望状态码: {expected_code} 【!=】 实际状态码: {code}")
raw_json = {'code': 200, 'body': {'code': 1, 'msg': '成功', 'data': {'total': 1, 'list': [
    {'id': 14151, 'name': 'test2020', 'mobile': '17382063236', 'email': '', 'tenantId': 331,
     'tenantName': 'TD17382063238',
     'headPicUrl': 'https://am-public-beta.oss-cn-beijing.aliyuncs.com/am/auth_pic/331/avatar/14151/avatar_1612495675824_55603.jpg',
     'source': 2, 'enableFlag': 1, 'type': 2, 'createUser': 14150, 'createUserName': 'okay',
     'createTime': '2020-12-15 17:16:25', 'auditStatus': None, 'orgUsers': None, 'linkFlag': None,
     'thingsboardUserId': 'fb70e730-9396-11eb-b459-050456b913b4'}]}}}

raw_json2 = {'code': 1, 'msg': '成功', 'data': {'total': 1, 'list': [
    {'id': 14151, 'name': 'test2020', 'mobile': '17382063236', 'email': '', 'tenantId': 331,
     'tenantName': 'TD17382063238',
     'headPicUrl': 'https://am-public-beta.oss-cn-beijing.aliyuncs.com/am/auth_pic/331/avatar/14151/avatar_1612495675824_55603.jpg',
     'source': 2, 'enableFlag': 1, 'type': 2, 'createUser': 14150, 'createUserName': 'okay',
     'createTime': '2020-12-15 17:16:25', 'thingsboardUserId': 'fb70e730-9396-11eb-b459-050456b913b4'}]}}

raw_dict = {'file': ('docker.jpeg', open('E:/work/SAAS/docker.jpeg', 'rb'), 'image/jpeg'),
             'appBiz': 'auth_pic',
             'appCode': 'am',
             'tenantId': '%(tenantId)s',
             'path': 'avatar/%(id)s',
             'bucketType': '1',
             }

def hh():
    res = jsonpath.jsonpath(raw_json, '$..tenantId')
    print(res)

depend_list = ["test_002:id", "test_003:tenantid"]


def hhh():
    for i in range(len(depend_list)):
        case_str_list = depend_list[i].split(":")[1].split(",")
        case_id = depend_list[i].split(":")[0]
        case_field = depend_list[i].split(":")[1]

        print(case_str_list, case_id, case_field)

def ttt():
    url = "/fp/v1/file/upload"
    if '/fp/v1/file/upload' in url:
        print("in")
    elif 'path' in url:
        print("good")

    else:
        print("not in")

def yyy():
    print(type(raw_dict))
    raw_str = str(raw_dict)
    h = raw_str%({'tenantId':'333','id':'5555'})
    print(h)

if __name__ == '__main__':
    yyy()
    # raw_value = '{{test_001:id}}'
    # value= raw_value.replace("{{", "").replace("}}", "").split(":")
    # print(raw_value, value)
    # need_filed = "msg"
    # re = 5
    # raw_res = """{"code": 102, 'msg': '操作对象不存在', 'data': {'id': {'hello':{0}}}}"""
    # # for key,value in raw_res.items():
    # #     if need_filed == key:
    # #         print(value)
    # deal_data = raw_res.format(8888)
    # print(deal_data)
    # hh()
    # hhh()


